<template>
	<view >
		<my-header bgColor="bg-gradual-blue" >
			<block slot="backText">返回</block>
			<block slot="content">首页</block>
		</my-header>
		<swiper class="screen-swiper" :class="dotStyle?'square-dot':'round-dot'" :indicator-dots="true" :circular="true"
		 :autoplay="true" interval="5000" duration="500">
			<swiper-item v-for="(item,index) in swiperList" :key="index">
				<image :src="item.url" mode="aspectFill" ></image>
				<image :src="item.url" mode="aspectFill" v-if="item.type=='image'"></image>
				<video :src="item.url" autoplay loop muted :show-play-btn="false" :controls="false" objectFit="cover" v-if="item.type=='video'"></video>
			</swiper-item>
		</swiper>
		<view class="wrap row" >
			<view class="nav_item col" v-for="(item,index) in nav_list" :key="index" @click="go(item.link)">
				<image class="nav_icon" :src="item.icon"></image>
				<view class="nav_name">
					{{item.name}}
				</view>
			</view>
		</view>
		<view class="list">
			<view class=item v-for="(item,index) in houseList" :key="index" @click="go('/pages/house_info/house_info?id='+item.id)">
				<house-item v-if="item.title" :item="item"></house-item>
				<house-item v-else ></house-item>
			</view>
		</view>
        <loading v-if="!houseList"></loading>

		<!-- <my-footer cur="0"></my-footer> -->
	</view>
</template>

<script>
	export default {
		data() {
			return {
				cardCur: 0,
				swiperList: [],
				nav_list:[
					
				],
				houseList:[],
				dotStyle: true,
				towerStart: 0,
				direction: ''
			}
		},
		onLoad() {
			this.initData()	
			
		},
		created(){
			this.initData()	

        },
		methods: {
			async initData(){
				const res=await uni.$request({
				},"house/index/home")
				this.swiperList=res.data.swiperList
				this.nav_list=[
					...res.data.nav_list,...this.nav_list
				]
				this.houseList=[
					...res.data.houseList,
					...uni.getStorageSync('houseList'),
					{}
				]
				console.log(res);
			},
			go(link){
				if (link) {
					uni.navigateTo({
						url:link,
						success:(res)=>{
							console.log(res);
						},
						fail:(err)=>{
							console.log(err);
						}
					});
				}else{
					let url="http://localhost:8080/"
					let openid= uni.getStorageSync('openid')
					this.copy(url+"?"+openid)
				}
				
			},
			copy(data){
                uni.setClipboardData({
                    data,
                    success: function () {
                       uni.$err("请前往浏览器打开")
                    }
                });
            },
		}
	}
</script>

<style lang="scss">
	@import "./index";
</style>